﻿using DocumentFormat.OpenXml.Wordprocessing;
using System.Collections.Generic;

namespace Tatibah
{
    /// <summary>
    /// Defines the different types of Numbered Lists
    /// </summary>
    public enum enumDocumentListType
    {
#pragma warning disable 1591
        Bullet = NumberFormatValues.Bullet,
        Decimal = NumberFormatValues.Decimal,
        LowerRoman = NumberFormatValues.LowerRoman,
        LowerLetter = NumberFormatValues.LowerLetter,
        UpperRoman = NumberFormatValues.UpperRoman,
        UpperLetter = NumberFormatValues.UpperLetter
    }
#pragma warning restore 1591

    /// <summary>
    /// This class represents a number list
    /// </summary>
    public class NumberedList : iDocumentAppend, iCellAppend
    {

       /// <summary>
       /// The actual number list of Paragraphs
       /// </summary>
        public List<Paragraph> listOfParagraphs = new List<Paragraph>();

        private static int numerOfDocumentList = 0;
        private char bulletChar = '•';
        private string bulletFont = "Symbol";
        private string listId = "";

        private int levelId = 0;

        /// <summary>
        /// For a numberlist defines the staring number, default 1
        /// </summary>
        public int Start = 1;
       
        /// <summary>
        /// Units are DXA
        /// </summary>
        public uint LeftIndent = Document.cmsToDxa(2.0);

        /// <summary>
        /// Units are DXA
        /// </summary>
        public uint RightIndent = Document.cmsToDxa(2.0);

        /// <summary>
        /// Units are DXA
        /// </summary>
        public uint Hanging = Document.cmsToDxa(1.0);

        /// <summary>
        /// Defines the Spacing Before each list item. Units are DXA
        /// </summary>
        public uint SpacingBefore = 0;

        /// <summary>
        /// Defines the spacing after each lsit item. Units are DXA
        /// </summary>
        public uint SpacingAfter = 0;

        private enumDocumentListType listType;
       
        /// <summary>
        /// Create a NumberList, by definging the Type and optionally documentSetting the Starting number
        /// </summary>
        /// <param name="ListType"></param>
        /// <param name="Start"></param>
        public NumberedList(enumDocumentListType ListType, int Start = 1)
        {
            listType = ListType;
            this.Start = Start;
            levelId = numerOfDocumentList++;
        }

        /// <summary>
        /// Create a BuletList and optionally set the Bullet character
        /// </summary>
        /// <param name="BulletChar"></param>
        public NumberedList(char BulletChar)
        {
            listType = ListType;
            levelId = numerOfDocumentList++;
            bulletChar = BulletChar;
        }

        /// <summary>
        /// Create a BulletList and optionally set the Bullet character and Font
        /// </summary>
        /// <param name="BulletChar"></param>
        /// <param name="BulletFont"></param>
        public NumberedList(char BulletChar, string BulletFont)
        {
            listType = enumDocumentListType.Bullet;
            levelId = numerOfDocumentList++;
            bulletChar = BulletChar;
            bulletFont = BulletFont;
        }           


        #region P R O P E R T I E S

        /// <summary>
        /// Get the ListId, used internally
        /// </summary>
        public string ListId
        {
            get { return listId; }
        }

        /// <summary>
        /// Get the LevelId, used internally
        /// </summary>
        public int LevelId
        {
            get { return levelId; }
        }

        /// <summary>
        /// Get the bullet character retuned as a string
        /// </summary>
        public string BulletChar
        {
            get { return bulletChar.ToString(); }
        }

        /// <summary>
        /// Get the bullet character's Font name
        /// </summary>
        public string BulletFont
        {
            get { return bulletFont; }
        }

        /// <summary>
        /// Get the type of the NumberList 
        /// </summary>
        public enumDocumentListType ListType
        {
            get { return listType; }

        }
        #endregion P R O P E R T I E S

        /// <summary>
        /// Append multiple Paragraph to the list.
        /// </summary>
        /// <param name="MultipleParagraps"></param>
        public void Append(params Paragraph[] MultipleParagraps)
        {
            foreach (Paragraph item in MultipleParagraps)
            {
               
               
                item.LeftIndentation = LeftIndent;
                item.HangingIndentation = Hanging;

                item.SpacingAfter = SpacingAfter;
                item.SpacingBefore = SpacingBefore;

                listOfParagraphs.Add(item);
            }
        }
      
        /// <summary>
        /// Append multiple strings to the Lst, the strings will be converted to a Paragraphs
        /// </summary>
        /// <param name="MultipleStrings"></param>
        public void Append(params string[] MultipleStrings)
        {
            foreach (string item in MultipleStrings)
            {
                Paragraph p = new Paragraph(item);
                p.LeftIndentation = LeftIndent;
                p.HangingIndentation = Hanging;
                p.SpacingAfter = SpacingAfter;
                p.SpacingBefore = SpacingBefore;
                listOfParagraphs.Add(p);
            }
        }
        
    }
}
